﻿using System.Collections.Generic;
using BoutiquePOS.DAL.DAO;
using BoutiquePOS.DAL.Gateway;

namespace BoutiquePOS.Manager
{
    public class ProductManager
    {
        ProductGateway productGateway = new ProductGateway();

        public Product GetUnitPrice(int categoryId, string productName)
        {
            return new ProductGateway().GetUnitPrice(categoryId, productName);
        }

        public string SaveProduct(Product product)
        {
            if (!DoesThisProductExist(product))
                return productGateway.SaveProduct(product);
            else
            {
                return "This Product Already Exists";
            }
        }
        private bool DoesThisProductExist(Product product)
        {
            List<Product> products = new List<Product>();
            products = productGateway.GetAllProduct();

            foreach (Product productObj in products)
            {              
                if (productObj.ProductBrandName == product.ProductBrandName)
                    return true;              
            }
            return false;
        }
        public List<Product> GetAllProduct()
        {
            return productGateway.GetAllProduct();
        }

        public string DeleteProduct(int productId)
        {
            string message = productGateway.DeleteProductById(productId);
            return message;
        }
    }
}